from django.shortcuts import redirect
from django.utils.deprecation import MiddlewareMixin


class AuthMD(MiddlewareMixin):
    white_list = ['/login/','/register/', ]  # 白名单
    # balck_list = ['/black/', ]  # 黑名单

    def process_request(self,request):
        next_url = request.path_info
        # print(next_url,request.get_full_path())
        if next_url in self.white_list or request.session.get("user"):
            return None
        elif "mock" in next_url:
            return None
        else:
            return redirect("login")

